Cron

The cron daemon is a background process that runs particular programs at particular times.

In [1]:
ls /etc/cron*
/etc/crontab

/etc/cron.d:
popularity-contest

/etc/cron.daily:
apt-compat    dpkg       man-db   passwd
bsdmainutils  logrotate  mlocate  popularity-contest

/etc/cron.hourly:

/etc/cron.monthly:
vrms

/etc/cron.weekly:
fstrim  man-db  tor
  • Root put (His/Other Users) jobs here: /etc/crontab (system-wide crontab)
  • extension of crontab: /etc/cron.d

  • Not in cron format. These are scripts that run once a dail, hour, etc.

    • cron.daily/
    • cron.hourly/
    • cron.weekly/
    • cron.monthly/
In [7]:
head -11 /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user	command
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
In [ ]:
echo "30 8-16 * * * milad updtime >> /home/milad/test" >> /etc/crontab 
# system wide, root access, will run by milad

Every 30 Min From 8 Am to 4 PM Every day of month, day of week

In [ ]:
crontab -e # user specific cron file
In [ ]:
# in top of crontab file will email the command output to milad
MAILTO=milad
In [ ]:
crontab -l # shows usere cron file
crontab -r # delete crontab file
In [ ]:
/etc/cron.deny  # users in this file can't use cron
/etc/cron.allow # if created only users in this file can use cron (NO ONE ELSE)

if both cron.allow and cron.deny files exist the cron.deny is ignored.

At

queue, examine or delete jobs for later execution

In [11]:
systemctl is-active atd.service
active

at HH:MM If that time is already past, the next day is assumed.
at midnight, noon, or teatime (4pm)
at now + count time-units

  • Time-units:
    • minutes, hours, days, or weeks
    • today by suffixing the time with today
    • tomorrow by suffixing the time with tomorrow

Examples:

  • at 1am tomorrow
  • at 17:04 sep 23
In [ ]:
at -l     : atq
at -d, -r : atrm
at -b     : batch
In [ ]:
/etc/at.deny  # users in this file can't use at
/etc/at.allow # if created only users in this file can use at (NO ONE ELSE)

Lecture notes

License

Creative Commons License

Linux Notes by Milad As (Ravexina) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


ravexina's gitlab

ravexina's github